<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Basic HW</title>
	<script type="text/javascript">
		function odd(){
			var node=document.createElement("LI");
			for (var i=1; i<21; i++)
			{	
				if (i%2==1)
				{
					var textnode=document.createTextNode(i+" ");
					node.appendChild(textnode);
					document.getElementById("odd").appendChild(node);
				}
			}
		}
		
		function sum(){
			var sum = 0,acc = 1;
			for (var i=1; i<11; i++)
			{	
				sum=sum+i;
				acc=acc*i;
			}
			document.getElementById("sum").innerHTML=("总和为："+sum);
			document.getElementById("acc").innerHTML=("乘积为："+acc);
		}
		
		function seven(){
			var str = "";
			for (var i=1; i<101; i++)
			{
				if (i%7!=0)
				{
					if (i<10)
					{
						str = str+"&nbsp;"+i+" ";
					}else{
						str = str+"&nbsp;"+i;
					}
				}else
				{
					str = str + "</br>";
				}
			}
			document.getElementById("seven").innerHTML= str;
		}
		
		function fifty(){
			var sum = 0,avg = 1;
			for (var i=50; i<81; i++)
			{	
				sum=sum+i;
			}
			avg = sum;
			document.getElementById("sum50").innerHTML=("总和为："+sum);
			document.getElementById("avg50").innerHTML=("均值为："+avg);
		}
		
		function hundred(){
			var str = "";
			var a=0;
			for(var i=100;i>0;i--){
				if(i%3==0){
					str = str + "&nbsp;" +i + " ";
					if(a<5){
						a++;
					}else{
						str = str + "</br>";
						a = 0;
					}
				}
			}
			document.getElementById("sum3").innerHTML=str;
		}
		
		function five(){
			var str = "";
			var a=0;
			for(var i=100;i>0;i--){
				if(i%5==0){
					str = str + "&nbsp;" +i + " ";
					if(a<5){
						a++;
					}else{
						str = str + "</br>";
						a = 0;
					}
				}
			}
			document.getElementById("sum5").innerHTML=str;
		}
		
		function bihunderd(){
			var str = "";
			var a,b,c;
			for (var i=200; i<301; i++){
				a = i%10;
				b = parseInt(i/10) %10;
				c = parseInt(i/100) %10;
				if(((a*b*c)==42)&&((a+b+c)==12)){
					str = str + "&nbsp;" + i + " ";
				}
			}
			document.getElementById("acc42").innerHTML=str;
		}
		
		function daffodil(){
			var str = "";
			var a,b,c,ans;
			for (var i=100; i<1000; i++){
				a = i%10;
				b = parseInt(i/10) %10;
				c = parseInt(i/100) %10;
				ans = Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3);
				if(ans==i){
					str = str + "&nbsp;" + i + " ";
				}
			}
			document.getElementById("daffodil").innerHTML=str;
		}

		function million(){
			var mi = String(document.getElementById("million2").value);
			var str = "";
			for (var i=mi.length-1;i>=0;i--){
				str= str + mi.charAt(i);
			}
			document.getElementById("million").innerHTML=str;
		}
		
		function date1(){
			var myDate = new Date();
			var year = document.getElementById("year").value;
			var month = document.getElementById("month").value;
			var day = document.getElementById("day").value;
			myDate.setFullYear(year,month-1,day);
			var count;
			var i = 1;
			count = 0;
			while(i<=month){
				if(i==month){
					count=count+ Number(day);
				}else if (i==2){
					if (((year%4==0)&&(year%100!=0))||(year%400==0)){
						count = count +29;
					}else {
						count = count + 28;
					}
				}else if (i==4,6,9,11)
				{
					count = count + 30;
				}else {
					count = count +31;
				}
				i++;
			}
			document.getElementById("cha1").innerHTML= ("这是"+ year + "年的第"+ count +"天");
		}
	</script>
 </head>
 <body>
	<div id="Q1">
		1、输出打印1--20中所有的奇数；  判断某个数是否是奇数，是奇数就输出<br/>
		<span id="odd" name="odd"></span><br/>
		<button onclick="odd()">submit</button><br/>
	</div>

	<div id="Q2">
		2、输出1---10的累加之和与1--10的累乘之积<br/>
		<span id="sum"></span></br>
		<span id="acc"></span><br/>
		<button onclick="sum()">submit</button><br/>
	</div>

	<div id="Q3">
		3、 输出不是7的整数倍的数字(1-100)。</br>
		<span id="seven"></span><br/>
		<button onclick="seven()">submit</button><br/>
	</div>

	<div id="Q4">
		4、计算50--80之间所有数据的总和以及平均值</br>
		<span id="sum50"></span></br>
		<span id="avg50"></span><br/>
		<button onclick="fifty()">submit</button><br/>
	</div>
	
	<div id="Q5">
		5、从大到小降序输出100以内所有能被3整除的正数</br>
		<span id="sum3"></span></br>
		<button onclick="hundred()">submit</button><br/>
	</div>
		
	<div id="Q6">
		6、按一行5个的方式降序输出100以内所有能被5整除的正数</br>
		<span id="sum5"></span></br>
		<button onclick="five()">submit</button><br/>
	</div>

	<div id="Q7">
		7、编写一个程序，求数出200到300之间的数，且满足条件：它们三个数字之积为42，三个数字之和为12</br>
		&nbsp如：237、327</br>
		<span id="acc42"></span></br>
		<button onclick="bihunderd()">submit</button><br/>
	</div>
	
	<div id="Q8">
		8、打印所有的水仙花数:</br>
			水仙花数是指在所有的三位数中，如果该数个位数的三次方+十位数的三次方+
			百位数的三次方和该数相等就称为水仙花数。</br>
		<span id="daffodil"></span></br>
		<button onclick="daffodil()">submit</button><br/>
	</div>
	
	<div id="Q9">
		9、输入一个6位数，用循环将其倒置输出</br>
		<span id="million"></span></br>
		<p><input type="number" style="width:80px;" maxlength="2" id="million2"/></p>
		<button onclick="million()">submit</button><br/>
	</div>
	
	<div id="Q10">
		10、让用户输入年份，月份，日期，输出该天是当年的第几天。</br>
		<span id="cha1"></span></br>
		年：
		<input name="year" type="number" style="width:50px;" maxlength="4" id="year"/>&nbsp;&nbsp;
		月：
		<input name="month" type="number" style="width:40px;" maxlength="2" id="month"/>&nbsp;&nbsp;
		日：
		<input name="day" type="number" style="width:40px;" maxlength="2" id="day"/>&nbsp;&nbsp;
		<br/>
		<br/>
		<button onclick="date1()">submit</button><br/>
	</div>
  <br/>
 </body>
</html>
